import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import "package:flutter/material.dart";

import '../../../../utils/NativeCall.dart';

// ignore: must_be_immutable
class PairingView extends StatelessWidget {
  double generalFontSize = 20;
  var apiAddressStr = "http://192.168.40.212:9001";
  Dio dio = new Dio();

  @override
  Widget build(BuildContext context) {
  
    return Container(
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: SingleChildScrollView(
          child: Column(
            children: [
              apiAddress("API", apiAddressStr, "后台服务api"),
              myTextView(context, "配对码", "请输入地址", "输入后台地址后激活"),
              apiAddress("餐厅编号", "请输入", ""),
              apiAddress("终端编号", "请输入", "后台服务api"),
              apiAddress("通讯密钥", "请输入", ""),
            ],
          ),
        ),
      ),
    );
  }

  Widget apiAddress(String title, String hit, String subTitle) {
    return Container(
        color: Colors.white,
        height: 84,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              height: 84,
              width: 250,
              child: Center(
                child: ListTile(
                  title:
                      Text(title, style: TextStyle(fontSize: generalFontSize)),
                  subtitle: Text(subTitle,
                      softWrap: false, overflow: TextOverflow.ellipsis),
                ),
              ),
            ),
            Container(
              height: 84,
              width: 290,
              padding: EdgeInsets.only(right: 10),
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                    Text(hit,
                        style: TextStyle(
                            fontSize: generalFontSize,
                            color: Colors.grey[400])),
                    Padding(
                      padding: EdgeInsets.only(left: 5),
                      child: Icon(Icons.arrow_forward_ios,
                          color: Colors.grey[500]),
                    )
                  ]),
            )
          ],
        ));
  }

  Widget myTextView(
      BuildContext context, String title, String hit, String subTitle) {
    return Container(
        color: Colors.white,
        height: 84,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              height: 84,
              width: 250,
              child: Center(
                child: ListTile(
                  title:
                      Text(title, style: TextStyle(fontSize: generalFontSize)),
                  subtitle: Text(subTitle,
                      softWrap: false, overflow: TextOverflow.ellipsis),
                ),
              ),
            ),
            Container(
              height: 84,
              width: 250,
              padding: EdgeInsets.only(right: 10),
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                    Padding(
                        padding: EdgeInsets.only(left: 5),
                        child: RaisedButton(
                          child: Text('配对码'),
                          onPressed: () {
                            showAlertDialog(context, "配对码", "输入后台获取的配对码");
                          },
                        ))
                  ]),
            )
          ],
        ));
  }



  void showAlertDialog(BuildContext context, String title, String hit) {
    showDialog<Null>(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          TextEditingController muController = TextEditingController();
          return AlertDialog(
            title: Text(title),
            //可滑动
            content: Container(
              width: 400,
              child: SingleChildScrollView(
                  child: TextField(
                controller: muController,
                decoration: InputDecoration(
                    hintText: hit,
                    hintStyle: TextStyle(color: Colors.grey),
                    hintMaxLines: 1),
              )),
            ),
            actions: <Widget>[
              FlatButton(
                child: Text('取消'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
              FlatButton(
                child: Text('确定'),
                onPressed: () {
                  NativeCall.getInstance().getPamars({
                    "type": "20",
                    "code": muController.text,
                    "shop": "107",
                    "term": "142",
                    "ver": "20201223",
                  });
                },
              ),
            ],
          );
        });
  }
}
